<template>
  <div class="admin-layout">
    <!-- 顶部导航栏 -->
    <el-header class="admin-header">
      <div class="header-left">
        <h3 class="logo">应急管理系统</h3>
      </div>
      <div class="header-right">
        <el-dropdown @command="handleCommand">
          <span class="user-info">
            <el-avatar size="small" :src="userAvatar">管理员</el-avatar>
            <span class="username">{{ username }}</span>
            <el-icon><ArrowDown /></el-icon>
          </span>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item command="profile">个人资料</el-dropdown-item>
              <el-dropdown-item command="logout">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </el-header>

    <div class="admin-container">
      <!-- 侧边栏菜单 -->
      <el-aside width="200px" class="admin-sidebar">
        <el-menu
          :default-active="$route.path"
          class="admin-menu"
          :collapse="sidebarCollapsed"
          @select="handleMenuSelect"
        >
          <!-- 仪表板 -->
          <el-menu-item index="/admin/dashboard">
            <el-icon><HomeFilled /></el-icon>
            <template #title>仪表板</template>
          </el-menu-item>

          <!-- 用户与权限管理 -->
          <el-sub-menu index="user-management">
            <template #title>
              <el-icon><User /></el-icon>
              <span>用户管理</span>
            </template>
            <el-menu-item index="/admin/users">用户列表</el-menu-item>
            <el-menu-item index="/admin/roles">角色管理</el-menu-item>
          </el-sub-menu>

          <!-- 急救知识管理 -->
          <el-sub-menu index="knowledge-management">
            <template #title>
              <el-icon><Document /></el-icon>
              <span>知识管理</span>
            </template>
            <el-menu-item index="/admin/knowledge/categories"
              >知识分类</el-menu-item
            >
            <el-menu-item index="/admin/knowledge/articles"
              >知识文章</el-menu-item
            >
            <el-menu-item index="/admin/knowledge/videos"
              >教学视频</el-menu-item
            >
            <el-menu-item index="/admin/knowledge/questions"
              >测试题库</el-menu-item
            >
          </el-sub-menu>

          <!-- 事件管理 -->
          <el-sub-menu index="event-management">
            <template #title>
              <el-icon><Warning /></el-icon>
              <span>事件管理</span>
            </template>
            <el-menu-item index="/admin/events/types">事件类型</el-menu-item>
            <el-menu-item index="/admin/events/records">事件记录</el-menu-item>
          </el-sub-menu>

          <!-- 志愿者管理 -->
          <el-sub-menu index="volunteer-management">
            <template #title>
              <el-icon><Avatar /></el-icon>
              <span>志愿者管理</span>
            </template>
            <el-menu-item index="/admin/volunteers/applications"
              >志愿者申请</el-menu-item
            >
            <el-menu-item index="/admin/volunteers/list"
              >志愿者列表</el-menu-item
            >
          </el-sub-menu>

          <!-- 通知管理 -->
          <el-sub-menu index="notification-management">
            <template #title>
              <el-icon><Bell /></el-icon>
              <span>通知管理</span>
            </template>
            <el-menu-item index="/admin/notifications/send"
              >发送通知</el-menu-item
            >
            <el-menu-item index="/admin/notifications/history"
              >通知历史</el-menu-item
            >
          </el-sub-menu>

          <!-- 系统设置 -->
          <el-menu-item index="/admin/settings">
            <el-icon><Setting /></el-icon>
            <template #title>系统设置</template>
          </el-menu-item>

          <!-- 文件管理 -->
          <el-menu-item index="/admin/files">
            <el-icon><Folder /></el-icon>
            <template #title>文件管理</template>
          </el-menu-item>
        </el-menu>
      </el-aside>

      <!-- 主内容区域 -->
      <el-main class="admin-main">
        <NuxtPage />
      </el-main>
    </div>
  </div>
</template>

<script setup lang="ts">
import {
  HomeFilled,
  User,
  Document,
  Warning,
  Avatar,
  Bell,
  Setting,
  Folder,
  ArrowDown,
} from "@element-plus/icons-vue";

const sidebarCollapsed = ref(false);
const username = ref("管理员");
const userAvatar = ref("");

const handleMenuSelect = (index: string) => {
  navigateTo(index);
};

const handleCommand = (command: string) => {
  switch (command) {
    case "profile":
      // 处理个人资料
      break;
    case "logout":
      // 处理退出登录
      navigateTo("/login");
      break;
  }
};
</script>

<style scoped>
.admin-layout {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.admin-header {
  background-color: #001529;
  color: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.header-left .logo {
  margin: 0;
  font-size: 18px;
  font-weight: bold;
}

.header-right .user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.header-right .username {
  font-size: 14px;
}

.admin-container {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.admin-sidebar {
  background-color: #f5f5f5;
  border-right: 1px solid #e6e6e6;
}

.admin-menu {
  border-right: none;
  height: 100%;
}

.admin-main {
  background-color: #f0f2f5;
  padding: 20px;
  overflow-y: auto;
}
</style>
